
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;

/**
 * Clase que se encarga de manejar la ventana de ayuda que aparece cuando
 * es precionado el boton de ayuda.
 *
 * @author Villalva Bueno Arely Eunice
 * @author Romero Rodriguez Gabriel Eduardo
 */
class Help extends JFrame implements ActionListener {

    JTextArea theText = new JTextArea();
    JButton OK = new JButton("OK");
    GUI dad;

    Help(GUI parent) {
        dad = parent;

        GridBagLayout gridbag = new GridBagLayout();
        GridBagConstraints constraints = new GridBagConstraints();
        setLayout(gridbag);

        dad.buildConstraints(constraints, 0, 0, 1, 1, 100, 90);
        constraints.fill = GridBagConstraints.BOTH;
        constraints.anchor = GridBagConstraints.CENTER;
        gridbag.setConstraints(theText, constraints);
        add(theText);

        dad.buildConstraints(constraints, 0, 1, 1, 1, 100, 10);
        constraints.fill = GridBagConstraints.NONE;
        constraints.anchor = GridBagConstraints.CENTER;
        gridbag.setConstraints(OK, constraints);
        OK.addActionListener(this);
        add(OK);

        theText.insert("Ayuda\n" +
                "----\n\n" +
                "Como usar el datapath.\n\n" +
                "Instrucciones soportadas:\n" +
                "------------ ----------\n\n" +
                "R-Type:\n" +
                "ADD,SUB,MULT,DIV,AND,OR,XOR,SLL,SRL,SLT,SLE,SGT,SGE,SEQ\n\n" +
                "I-Type:\n" +
                "ADDI,ANDI,ORI,XORI,SUBI,SLLI,SRLI\n\n" +
                "Operaciones De Memoria(I-Type):\n" +
                "LW,SW\n\n" +
                "Branching (I-Type):\n" +
                "BNE,BEQ\n\n" +
                "Formato para instrucciones R-Type:\n" +
                "<op> $<dest> $<source1> $<source2>\n" +
                "ADD $3 $2 $1\n\n" +
                "Formato para instrucciones I-Type:\n" +
                "<op> $<dest> $<source> <immediate>\n" +
                "ADDI $1 $1 100\n\n" +
                "Formato para instrucciones de memoria:\n" +
                "<op> $<data reg> <immediate>($<offset reg>)\n" +
                "LW $1 100($2)\n\n" +
                "Formato para instrucciones de Branching:\n" +
                "<op> $<source1> $<source2> immediate\n" +
                "BNE $2 $1 100\n\n", 0);

        this.pack();
        setSize(new Dimension(500, 650));
    }

    /**
     * Maneja los eventos de el boton OK.
     */
    public void actionPerformed(ActionEvent e) {
        Object src = e.getSource();
        if (src == OK) {
            this.setVisible(false);
        }
    }
}
